#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <pthread.h>
#include <errno.h>
#include <time.h>

#define SERVPORT 9999

int main(int argc, char *argv[])
{
	int sockfd;

	struct sockaddr_in serv_addr;

	if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
	{
		perror("socket error!");
		return -1;
	}

	serv_addr.sin_family = AF_INET;
	serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
	serv_addr.sin_port = htons(SERVPORT);
	bzero(&(serv_addr.sin_zero),8);

	if(-1 == connect(sockfd,(struct sockaddr*)&serv_addr,sizeof(struct sockaddr)))
	{
		perror("connect error");
		return -1;
	}

	char buf[512];
	memset(buf, 0, 512);
	while(1)
	{
		strncpy(buf, "this is client", 15);
		if(-1 == send(sockfd, &buf, 15, 0))
		{
			perror("send error");
			return -1;
		}
		memset(buf,0,512);
		sleep(2);
	}
	close(sockfd);
	return 0;
}
